package com.frinder.robot.strategy.task.convert;

import lombok.Data;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @ClassName ConvertToRobotTaskPayload
 * @Description 外部任务转化为机器人任务请求对象
 * @Author frinder
 * @Date 2019/10/18 10:39
 * @Verion 1.0
 */
@Data
public class ConvertToRobotTaskPayload {

    private Type type;

    public enum Type {
        NA(0),
        TRANSPORT(1),
        TRANSPORT_BACK(2),
        TRANSPORT_SCAN(3),
        TRANSPORT_SCAN_BACK(4);

        @Getter
        private int value;

        Type(int value) {
            this.value = value;
        }

        static final List<Type> TYPES = Arrays.asList(values());

        public static Type parse(final int type) {
            Optional<Type> op = TYPES.stream()
                    .filter(item -> type == item.getValue())
                    .findFirst();
            if (op.isPresent()) {
                return op.get();
            } else {
                return NA;
            }
        }
    }
}

